﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Linq.Expressions;

namespace AL.Service {

    public class Messages {

        /// <summary>
        /// HH: 构造函数 - 初始化
        /// </summary>
        public Messages() {
        }




        /// <summary>
        /// HH: 新增对象
        /// </summary>
        public Entity.Message Insert(Entity.Message m) {
            DAL.Provider.Messages.Create(m);
            return m;
        }


        /// <summary>
        /// HH: 修改对象
        /// </summary>
        /// <param name="m"></param>
        public void Update(Entity.Message m){
            DAL.Provider.Messages.Update(m);
        }


        /// <summary>
        /// HH: 删除对象
        /// </summary>
        public void Delete(Entity.Message m) {
            DAL.Provider.Messages.Delete(m);
        }
        /// <summary>
        /// HH: 删除对象
        /// </summary>
        public void Delete(int id) {
            DAL.Provider.Messages.Delete(o => o.ID == id);
        }


        /// <summary>
        /// HH: 获取一个对象实例
        /// </summary>
        public Entity.Message GetByID(int id) {
            return DAL.Provider.Messages.Get(o => o.ID == id);
        }

        /// <summary>
        /// HH: 分页获取对象集合
        /// </summary>
        public IEnumerable<Entity.Message> PageList<TKey>(Expression<Func<Entity.Message, TKey>> orderBy, bool isAsc, Expression<Func<Entity.Message, bool>> where, int pageIndex, int pageSize, out int rowsCount) {
            //var list = DAL.Provider.Messages.PageList(o => o.ID, false, o => o.ID > 0, pageIndex, pageSize, out rowsCount);
            //var ret = from item in list
            //          select new { id = item.ID, value = item.Title };
            //return Json(new { total = rowsCount, rows = ret }, JsonRequestBehavior.AllowGet);

            return DAL.Provider.Messages.PageList(orderBy, isAsc, where, pageIndex, pageSize, out rowsCount);
        }

    }
}
